import { fabric } from 'fabric';

import ObjectPool from './ObjectPool';

class Trapezoid extends fabric.Polygon {
  constructor(options = {}) {
    const points = [
      { x: -30, y: -25 },  // 左上
      { x: 30, y: -25 },   // 右上
      { x: 50, y: 25 },    // 右下
      { x: -50, y: 25 },   // 左下
    ];

    super(points, {
      fill: '#16a085',
      strokeWidth: 1,
      stroke: '#000000',
      selectable: true,
      cornerSize: 10,
      transparentCorners: false,
      hasRotatingPoint: true,
      padding: 5,
      id: '',  // 添加id属性
      ...options,
    });

    // 确保控制点颜色与边框颜色一致
    this.set({
      cornerColor: this.stroke,
      borderColor: this.stroke,
    });
  }

  // ... existing code ...
}

// 创建一个全局的梯形对象池
const trapezoidPool = new ObjectPool(() => new Trapezoid());

// 导出Trapezoid类和trapezoidPool
export { Trapezoid, trapezoidPool };
export default Trapezoid;
